import { useState } from 'react'
const Child = () => {
  const [count, setCount] = useState(0)

  // 3 秒后，获取 count 值
  const getCount = () => {
    setTimeout(() => {
      // 每次获取都是当前点击的时候count的值
      console.log('3秒之后的值：', count)
    }, 3000)
  }

  // 计数器 +1
  const handleClick = () => {
    setCount(count + 1)
  }

  return (
    <div>
      <button onClick={handleClick}>+1</button>
      <button onClick={getCount}>延迟获取 count 值</button>
      <h1>计数器：{count}</h1>
    </div>
  )
}

export default Child
